<?php
	
	function unEquip($type)
	{
		switch($type)
		{
			case 1:
				$type = 'weaponid';
				break;
			case 0:
				$type = 'armorid';
				break;
		}

		$cid = $_SESSION['cid'];
		mysql_query("UPDATE characters SET $type='0' WHERE id='$cid'");
	}

	function Equip($iid, $type)
	{
		switch($type)
		{
			case 1:
				$type = 'weaponid';
				break;
			case 0:
				$type = 'armorid';
				break;
		}

		$cid = $_SESSION['cid'];
		mysql_query("UPDATE characters SET $type='$iid' WHERE id='$cid'");
	}

	if($_GET['page'] == 'items' AND isset($_GET['unequip']) AND isset($_GET['type']))
	{
		unEquip($_GET['type']);
	}

	if($_GET['page'] == 'items' AND isset($_GET['equip']) AND isset($_GET['type']))
	{
		Equip($_GET['equip'], $_GET['type']);
	}

	function getWeapons()
	{
		$cid = $_SESSION['cid'];
		$q = mysql_query("SELECT * FROM item, item_own WHERE item_own.iid = item.id AND item_own.cid = '$cid' AND item_own.type = '1'");
		while($f = mysql_fetch_array($q))
		{
			echo '<table style="border: 1px solid white; width:100%; float:left; margin-bottom:10px;">
				<tr><td rowspan="6" width="180px"><img src="img/weapons/'.$f['image'].'" width="150px"></td></tr>
				<tr><td colspan="4"><h3>'.$f['name'].'</h3></td></tr>
				<tr><td width="150">Attack Bonus:</td><td width="50">'.$f['attackbonus'].'</td><td>';

					if($f['id'] == getCharWeapon($cid))
					{
						echo '<a href="?page=items&unequip&type='.$f['type'].'"><button class="bsexy">Un-Equip</button></a>';
					}
					else
					{
						echo '<a href="?page=items&equip='.$f['id'].'&type='.$f['type'].'"><button class="bsexy">Equip</button></a>';
					}

				echo '</td></tr>
				<tr><td>Defence Bonus:</td><td>'.$f['defencebonus'].'</td><td width="100">
				</td><td></td></tr>
				<tr><td>Success Bonus:</td><td>'.$f['succesrate'].'%</td></tr>
			</table>';
		}
	}

	function getArmour()
	{
		$cid = $_SESSION['cid'];
		$q = mysql_query("SELECT * FROM item, item_own WHERE item_own.iid = item.id AND item_own.cid = '$cid' AND item_own.type = '0' ");
		while($f = mysql_fetch_array($q))
		{
			echo '<table style="border: 1px solid white; width:100%; float:left; margin-bottom:10px;">
				<tr><td rowspan="6" width="180px"><img src="img/armour/'.$f['image'].'" width="150px"></td></tr>
				<tr><td colspan="4"><h3>'.$f['name'].'</h3></td></tr>
				<tr><td width="150">Attack Bonus:</td><td width="50">'.$f['attackbonus'].'</td><td>';

					if($f['id'] == getCharArmor($cid))
					{
						echo '<a href="?page=items&unequip&type='.$f['type'].'"><button class="bsexy">Un-Equip</button></a>';
					}
					else
					{
						echo '<a href="?page=items&equip='.$f['id'].'&type='.$f['type'].'"><button class="bsexy">Equip</button></a>';
					}

				echo '</td></tr>
				<tr><td>Defence Bonus:</td><td>'.$f['defencebonus'].'</td><td width="100">
				</td><td></td></tr>
				<tr><td>Success Bonus:</td><td>'.$f['succesrate'].'%</td></tr>
			</table>';
		}
	}
?>